<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiRoleRolesFieldsTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_role_roles_fields';

    /**
     * Run the migrations.
     * @table qii_role_roles_fields
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id')->comment('ID');
            $table->unsignedInteger('roles_id')->default('0')->comment('角色ID');
            $table->string('field_name', 100)->default('')->comment('字段名称');
            $table->string('field_key', 20)->default('')->comment('key');
            $table->unsignedInteger('field_key_crc32')->default('0')->comment('crc32');
            $table->enum('field_type', ['char', 'text', 'number', 'select', 'radio'])->nullable()->default(null)->comment('字段类型');
            $table->text('field_value')->comment('默认值');
            $table->text('field_config')->comment('字段配置(select或radio的选项)');
            $table->unsignedInteger('is_alone')->default('1')->comment('是否独立字段');

            $table->index(["roles_id", "field_key_crc32"], 'roles_alone');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
